package com.yang.web.controller;

import com.yang.web.exception.UserNotException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>@ProjectName:spring-boot-web-demo</p>
 * <p>@Package:com.yang.web.controller</p>
 * <p>@ClassName:SuccessController</p>
 * <p>@Description:</p>
 * <p>@Author:yang</p>
 * <p>@author:yang</p>
 * <p>@Date:2021/12/31 13:14</p>
 * <p>@Version:1.0</p>
 */
@Controller
public class SuccessController {

    @GetMapping("success")
    public String success(Map<String, Object> map) {
        map.put("hello", "<h1>你好</h1>");
        map.put("users", Arrays.asList("yang", "cheng", "lin"));
        return "success";
    }

    @RequestMapping({"/", "/index.html"})
    public String index(Map<String, Object> map) {
        map.put("hello", "<h1>你好</h1>");
        map.put("users", Arrays.asList("yang", "cheng", "lin"));
        return "login";
    }

    @GetMapping("hello/{username}")
    public String success(@PathVariable("username") String username) {
        if (username.equals("aaa")) {
            throw new UserNotException();
        }
        return "success";
    }


}
